/**
 * <p>Title: ServiceZP18.java</p>
 * <p>Description: </p>
 * <p>Copyright: Baosight Software LTD.co Copyright (c) 2002</p>
 * <p>Company: Baosight Software</p>
 * @author 张志芳
 * @version 1.0
 * <pre>Histroy:
 *          2012-10-17 上午07:24:58  张志芳  Create
 *</pre>
 */
package com.baosight.sczx.zp.service;

import java.util.List;

import com.baosight.iplat4j.core.ei.EiBlock;
import com.baosight.iplat4j.core.ei.EiConstant;
import com.baosight.iplat4j.core.ei.EiInfo;
import com.baosight.iplat4j.ep.QueryMap;
import com.baosight.iplat4j.ep.ServiceEPBase;
import com.baosight.iplat4j.es.domain.ESPost;
import com.baosight.iplat4j.security.bridge.SecurityBridge;
import com.baosight.iplat4j.security.bridge.SecurityBridgeFactory;
import com.baosight.sczx.common.zp.ZPUtils;
import com.baosight.sczx.zp.domain.ZPUserset;

/**
 * 用户权限管理——角色
 * <p>Title: ServiceZP18.java</p>
 * <p>Description: </p>
 * <p>Copyright: Baosight Software LTD.co Copyright (c) 2002</p>
 * <p>Company: Baosight Software</p>
 * @author 张志芳
 * @version 1.0
 * <pre>Histroy:
 *          2012-10-17 上午07:24:58  张志芳  Create
 *</pre>
 */
public class ServiceZP18 extends ServiceEPBase {

	SecurityBridge bridge = SecurityBridgeFactory.getBridge();
	/**
	 * 初始化
	 * <p>Function: initLoad</p>
	 * <p>Description: </p>
	 * <p>return value: ServiceZP14</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2012-10-8上午07:59:00 张志芳
	 * </p>
	 *
	 */
	public EiInfo initLoad(EiInfo inInfo)
	{
		inInfo.addBlock(EiConstant.resultBlock).set("showCount", "true");//如果不加这个，翻页的统计和显示是错误的
		EiInfo outInfo = this.query(inInfo);
		return outInfo;
	}
	
	/**
	 * 查询
	 * <p>Function: query</p>
	 * <p>Description: </p>
	 * <p>return value: ServiceZP14</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2012-10-8上午07:59:12 张志芳
	 * </p>
	 *
	 */
	public EiInfo query(EiInfo inInfo)
	{
		//构造返回值outInfo
		EiInfo outInfo = new EiInfo();
		outInfo.setAttr(inInfo.getAttr());
		outInfo.setBlock(inInfo.getBlock(EiConstant.queryBlock));
		EiBlock block = outInfo.addBlock(EiConstant.resultBlock);
		block.setBlockMeta(new ZPUserset().eiMetadata);
		
		//提取查询条件
		QueryMap queryMap = QueryMap.getQueryMap(inInfo);
		
		String userId = inInfo.getString("userId");
		List<ESPost> list = bridge.getUserRoles(userId, "", queryMap.getOffset(), queryMap.getLimit());
		
		for(int n=0; n<list.size(); n++){
			ZPUserset user = new ZPUserset();
			user.setPostLabel(list.get(n).getPostLabel());
			user.setOrgLabel(list.get(n).getOrgLabel());
			user.setPostTypeLabel(list.get(n).getPostTypeLabel());
			user.setPostTypeName(bridge.getRoleTypeDisplayName(list.get(n).getPostTypeLabel()));
			block.addRow(user);
		}
		int totalnum = bridge.getUserRoleCount(userId);
		queryMap.setCount(totalnum);
		queryMap.setEiInfo(outInfo, EiConstant.resultBlock);
		
		return outInfo;
	}
	
	
}
